package com.tencent.wxcloudrun.service.impl;

import com.tencent.wxcloudrun.dto.*;
import com.tencent.wxcloudrun.mapper.ChildscurgoodsMapper;
import com.tencent.wxcloudrun.mapper.GoodsMapper;
import com.tencent.wxcloudrun.mapper.GoodscategoryMapper;
import com.tencent.wxcloudrun.mapper.PropertiesMapper;
import com.tencent.wxcloudrun.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lichongbing
 * @version 1.0.0
 * @createdate 2023/3/13 10:23
 * @description: TODO
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private GoodscategoryMapper goodscategoryMapper;
    @Autowired
    private PropertiesMapper propertiesMapper;

    @Autowired
    private ChildscurgoodsMapper childscurgoodsMapper;
    @Override
    public List<Goodscategory> getGoodsCategory() {
        return  goodscategoryMapper.getGoodsCategory();
    }

    @Override
    public Goods getById(String goodsId) {
        return  goodsMapper.getById(goodsId);
    }

    @Override
    public Goodscategory getByGoodscategoryId(Integer categoryid) {
        return  goodscategoryMapper.getByGoodscategoryId(categoryid);
    }

    @Override
    public List<PropertiesVo> getProperties(String goodsId) {
     List<Properties> properties =  propertiesMapper.getProperties(goodsId);
     List<PropertiesVo> propertiesVos = new ArrayList<>();
        for (int i = 0; i < properties.size(); i++) {
            List<Childscurgoods> childscurgoods = childscurgoodsMapper.getChildscurgoods(properties.get(i).getId());
            PropertiesVo propertiesVo = new PropertiesVo();
            propertiesVo.setChildscurgoods(childscurgoods);
            propertiesVo.setId(properties.get(i).getId());
            propertiesVo.setName(properties.get(i).getName());
            propertiesVo.setPaixu(properties.get(i).getPaixu());
            propertiesVo.setUserid(properties.get(i).getUserid());
            propertiesVos.add(propertiesVo);
        }
        return propertiesVos;
    }

    @Override
    public List<Goods> getGoodsByCategoryId(Integer categoryId, Integer shopId) {
        return goodscategoryMapper.getGoodsByCategoryId(categoryId,shopId);
    }

    @Override
    public Goodscategory getGoodsCategoryDetail(String id) {
        return goodscategoryMapper.getByGoodscategoryId(Integer.valueOf(id));
    }
}
